<template>
    <div>

        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id===0?'mui-active':'']" v-for="item in piclist" :key="item.id" @click="getimg(item.id)">
                        {{item.title}}
                    </a>

                </div>
            </div>
        </div>

        <ul class="lazy">
            <router-link :to="'/home/photolist/photoinfo/'+item.id" v-for="item in list" :key="item.id" tag="li">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h3 class="info-title">{{item.title}}</h3>
                    <div class="info-body">{{item.zhaiyao}}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>

<script>
    import mui from "../../lib/mui/js/mui.min"
    import axios from "axios"

    export default {
        name: "photolist",
        data(){
            return{
                piclist:[], //标题
                list:[] //  图片存放
            }
        },
        methods:{

            init(){
                mui('.mui-scroll-wrapper').scroll({
                    deceleration: 0.0005, //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
                    scrollX: true,
                    scrollY:false
                });
            },
            getpic(){
                axios.get("api/getimgcategory")
                    .then( suc=>{
                        // console.log(suc.data.message)
                        this.piclist = suc.data.message
                        this.piclist.unshift({title:"全部", id:0});
                    })
                    .catch(err=>{
                        console.log(err)
                    })
            },
            getimg(cateid){
                axios.get("api/getimages/"+cateid)
                    .then(suc=>{
                        // console.log(suc)
                        this.list = suc.data.message;
                    })
                    .catch(err=>{
                        console.log(err)
                    })
            }
        },
        created(){
            this.getpic();
            this.getimg(0);
        },
        mounted() {
            this.init()
        }
    }
</script>

<style scoped lang="less">
    *{
        touch-action: pan-y;
    }
    .lazy{
        list-style: none;
        padding: 10px 10px 0 10px;
        text-align: center;

        img[lazy=loading] {
            width: 40px;
            height: 300px;
            margin: auto;
        }
        li{
            margin-bottom: 10px;
            position: relative;

            &:last-child{
                margin-bottom: 0;
            }

            img{
                width: 100%;
            }

            .info{
                position: absolute;
                left: 0;
                bottom: 0;
                background-color: rgba(1,1,2, .5);
                max-height: 84px;
                color: #fff;

                .info-title{
                    font-size: 14px;
                }
                .info-body{
                    font-size: 12px;
                }
            }

        }
    }
</style>